package com.jkhan.demo.collection;

import java.util.ArrayList;
import java.util.Collection;

public class TestCollection {
    public static void main(String[] args) {
        ArrayList<String> collection1 = new ArrayList<>();
        collection1.add("New York");
        collection1.add("Madison");
        collection1.add("Atlanta");
        collection1.add("BeiJin");

        System.out.println("A list of cities in collection1: ");
        System.out.println(collection1);

        System.out.println("\nIs Madison in collection1? " + collection1.contains("Madison"));

        collection1.remove("Madison");
        System.out.println("\n" + collection1.size() + "cities are in collection1 now");

        Collection<String> collection2 = new ArrayList<>();
        collection2.add("Portland");
        collection2.add("Atlanta");
        collection2.add("Seattle");
        collection2.add("Los Angeles");

        System.out.println("A list of cities in collection2: ");
        System.out.println(collection2);

        ArrayList<String> arrayList = (ArrayList<String>) collection1.clone();
        arrayList.addAll(collection2);
        System.out.println("\n Cities in collection1 or collection2: ");
        System.out.println(arrayList);

        arrayList = (ArrayList<String>) collection1.clone();
        arrayList.retainAll(collection2);
        System.out.println("\n Cities in collection1 and collection2: ");
        System.out.println(arrayList);

        arrayList = (ArrayList<String>) collection1.clone();
        arrayList.removeAll(collection2);
        System.out.println("\n Cities in collection1, but not in collection2: ");
        System.out.println(arrayList);

    }
}
